package com.clkj.sunhelp.adapter.list;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.clkj.sunhelp.R;
import com.clkj.sunhelp.bean.PolicyListItem;

import java.util.List;

/**
 * Created by Administrator on 2017/3/26.
 */

public class ListAdapterForPolicy extends BaseAdapter {


    List<PolicyListItem> mPolicyList;
    Context mContext;
    LayoutInflater mLayoutInflater;

    public ListAdapterForPolicy(Context context, List<PolicyListItem> policyList) {
        mContext = context;
        this.mPolicyList = policyList;
        mLayoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mPolicyList.size();
    }

    @Override
    public Object getItem(int i) {
        return mPolicyList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder viewHolder = null;
        if (view == null)
        {
            view = mLayoutInflater.inflate(R.layout.list_item_policy,null);
            viewHolder = new ViewHolder();
            viewHolder.tvPolicyTitle = (TextView) view.findViewById(R.id.tv_policy_title);
            viewHolder.tvPolicyPubTime = (TextView) view.findViewById(R.id.tv_policy_pub_time);


            view.setTag(viewHolder);

        }else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.tvPolicyTitle.setText(mPolicyList.get(i).getFullHead());
        viewHolder.tvPolicyPubTime.setText(mPolicyList.get(i).getReleaseTime());

        return view;
    }


    static class ViewHolder{
        private TextView tvPolicyTitle;
        private TextView tvPolicyPubTime;


    }
}
